package com.xiumu.securitydemo.config.security.handler;

import com.xiumu.securitydemo.model.bean.ResultJSON;
import com.xiumu.securitydemo.utils.SecurityHandlerUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static com.xiumu.securitydemo.utils.args.ResultArgsUtil.USER_NOT_EXIST_FAILURE_CODE;
import static com.xiumu.securitydemo.utils.args.ResultArgsUtil.USER_NOT_EXIST_FAILURE_MSG;

/**
 * @Author xiumu
 * @Date 2020/5/28 10:57
 */
public class LoginFailureHandlerImpl implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        SecurityHandlerUtil.responseHandler(httpServletResponse,new ResultJSON(USER_NOT_EXIST_FAILURE_CODE,USER_NOT_EXIST_FAILURE_MSG));
    }
}
